package com.busi.controller.ruleset;

import com.busi.entity.RuleSet;
import com.busi.util.HttpUtils;
import com.busi.util.PropertyUtil;
import com.zcurd.controller.BaseController;

/**   
 * @Title: ruleset
 * @Description: ruleset
 * @author xusai
 * @date 2017-10-09 16:51:56
 * @version V1.0   
 *
 */
public class RuleSetController extends BaseController {
		//列表
		public void list() {
			render("list.html");
		}
		
		//回显列表
		public void listData(){
			RuleSet ruleSet=getBean(RuleSet.class,"");
			String body = gson.toJson(ruleSet);
			String domain = PropertyUtil.getStrValue("new_zx.domain", "");
			String url = domain + "/api/ruleSet/findList";
			String[][] headers = {{"Content-Type", "application/json"}};
			String jsonString = HttpUtils.doPost(url, body, headers , 3, 5, "utf-8");
			renderJson(jsonString==null?"":jsonString);		
		}
		//增加页面
		public void addPage() {
			
			render("add.html");
		}
		
		//增加页面
		public void add() {
			RuleSet ruleSet=getBean(RuleSet.class,"");
			String body = gson.toJson(ruleSet);
			String domain = PropertyUtil.getStrValue("new_zx.domain", "");
			String url = domain + "/api/ruleSet/addPage";
			
			String[][] headers = {{"Content-Type", "application/json"}};
			String jsonString = HttpUtils.doPost(url, body, headers , 3, 5, "utf-8");
			renderSuccess();
		}
		
		//编辑
		public void update() {
			render("update.html");
		}
		
		//查看详情
		public void detail() {
			RuleSet ruleSet=getBean(RuleSet.class,"");
			setAttr("setId", ruleSet.getSetId());
			render("detail.html");
		}
		//回显列表
		public void detailList(){
			RuleSet ruleSet=getBean(RuleSet.class,"");
			String body = gson.toJson(ruleSet);
			String domain = PropertyUtil.getStrValue("new_zx.domain", "");
			String url = domain + "/api/ruleSet/findList3";
			String[][] headers = {{"Content-Type", "application/json"}};
			String jsonString = HttpUtils.doPost(url, body, headers , 3, 5, "utf-8");
			renderJson(jsonString==null?"":jsonString);		
		}
		
		//导入详情
		public void detail2() {
			RuleSet ruleSet=getBean(RuleSet.class,"");
			setAttr("setId", ruleSet.getSetId());
			render("detail2.html");
		}
		//导入详情回显列表
		public void detail2List(){
			RuleSet ruleSet=getBean(RuleSet.class,"");
			setAttr("setId", ruleSet.getSetId());
			String body = gson.toJson(ruleSet);
			String domain = PropertyUtil.getStrValue("new_zx.domain", "");
			String url = domain + "/api/ruleSet/findList2";
			String[][] headers = {{"Content-Type", "application/json"}};
			String jsonString = HttpUtils.doPost(url, body, headers , 3, 5, "utf-8");
			renderJson(jsonString==null?"":jsonString);		
		}
		
		//导入规则
		public void datasave(){
			RuleSet ruleSet=getBean(RuleSet.class,"");
			//System.out.println(ruleSet.getDataarr()+"=================================????????????????????"+ruleSet.getSetId());
			ruleSet.setDataId(ruleSet.getDataarr());
			String body = gson.toJson(ruleSet);
			String domain = PropertyUtil.getStrValue("new_zx.domain", "");
			String url = domain + "/api/ruleSet/datasavePage";
			String[][] headers = {{"Content-Type", "application/json"}};
			String jsonString = HttpUtils.doPost(url, body, headers , 3, 5, "utf-8");
			render("list.html");
		}
		
		//删除规则
		public void delete(){
			RuleSet ruleSet = getBean(RuleSet.class,"");
			String body = gson.toJson(ruleSet);
			String domain = PropertyUtil.getStrValue("new_zx.domain", "");
			String url = domain + "/api/ruleSet/deletePage";
			String[][] headers = {{"Content-Type", "application/json"}};
			String jsonString = HttpUtils.doPost(url, body, headers, 3, 5, "utf-8");
			System.out.println(jsonString+"！！！！！=============");
			//JSONObject ret =(JSONObject) JSONObject.parse(jsonString);
			/*RuleData ruleData1 = gson.fromJson(jsonString, RuleData.class);
			setAttr("ruleData", ruleData1);*/
			renderSuccess();
			/*if("0000".equals(ret.get("ret"))){
				renderSuccess();
			}else{
				renderFailed(jsonString=="操作失败！"?"":jsonString);
			}*/
		}
}
